{include file="public/layout" /}
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-10">
    {include file="language/bar" /}
    <div class="flexigrid">
        <div class="mDiv pt0">
            <div class="ftitle">
                {eq name='$main_lang' value='$admin_lang'}
                    {eq name="'Language@add'|is_check_access" value="1"}
                    <div class="fbutton">
                        <a href="javascript:void(0);" data-href="{:url('Language/add')}" onclick="openFullframe(this, '新增语言', '600px', '570px');">
                            <div class="add">
                                <span><i class="layui-icon layui-icon-addition"></i>新增语言</span>
                            </div>
                        </a>
                    </div>
                    {/eq}
                {/eq}
            </div>
            <form class="navbar-form form-inline" action="{:url('Language/index')}" method="get" onsubmit="layer_loading('正在处理');">
                {$searchform.hidden|default=''}
                <div class="sDiv">
                    <div class="sDiv2">
                        <input type="text" size="30" name="keywords" value="{$Request.param.keywords}" class="qsbox" placeholder="中文名称搜索...">
                        <input type="submit" class="btn" value="搜索">
                        <i class="iconfont e-sousuo"></i>
                    </div>
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        {eq name='$main_lang' value='$admin_lang'}
                        <th class="sign w40" axis="col0">
                            <div class="tc"><input type="checkbox" class="checkAll"></div>
                        </th>
                        {/eq}
                        <th abbr="article_show" axis="col5" class="w40">
                            <div class="tc">ID</div>
                        </th>
                        <th abbr="ac_id" axis="col4">
                            <div class="text-l10">语言名称</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w80">
                            <div class="tc">语言标识</div>
                        </th>
                        <th abbr="article_title" axis="col3" class="w180">
                            <div class="text-l10">中文名称</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w60">
                            <div class="tc">国旗</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">前台默认语言</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w50">
                            <div class="tc">开启</div>
                        </th>
                        <!-- <th abbr="article_time" axis="col6" class="w200">
                            <div class="tc">单独域名</div>
                        </th> -->
                        <th axis="col1" class="w150">
                            <div class="tc">操作</div>
                        </th>
                        <th abbr="article_show" axis="col5" class="w60">
                            <div class="tc">排序</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <div class="no_row">
                                    <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                </div>
                            </td>
                        </tr>
                    {else/}
                        {foreach name="list" item="vo" key="k" }
                        <tr>
                            {eq name='$main_lang' value='$admin_lang'}
                            <td class="sign">
                                <div class="w40 tc">
                                    {if condition="1 != $vo.is_home_default AND 0 < $k"}
                                    <input type="checkbox" autocomplete="off" name="ids[]" value="{$vo.id}">
                                    {else/}
                                    <input disabled  type="checkbox" name="ids[]" value="{$vo.id}">
                                    {/if}
                                </div>
                            </td>
                            {/eq}
                            <td class="sort">
                                <div class="w40 tc">
                                    {$vo.id}
                                </div>
                            </td>
                            <td style="width: 100%">
                                <div class="text-l10" style="">
                                    <a href="javascript:void(0);" data-href="{:url('Language/edit',array('id'=>$vo['id']))}" onclick="openFullframe(this, '编辑语言', '600px', '530px');">
                                    {$vo.title}</a>
                                </div>
                            </td>
                            <td class="tc">
                                <div class="w80 tc">
                                    {$vo.mark}
                                </div>
                            </td>
                            <td class="">
                                <div class="w180 text-l10">
                                    {$languagemarkList[$vo['mark']]['cn_title']}
                                </div>
                            </td>
                            <td class="tc">
                                <div class="w60 tc">
                                    <img src="__STATIC__/common/images/language/{$vo.mark}.gif" alt="{$vo.cn_title}" style="float: unset;"/>
                                </div>
                            </td>
                            <td class="">
                                <div class="w100 tc">
                                    {eq name="$vo['is_home_default']" value='1'}
                                        <span class="yes">是</span>
                                    {else /}
                                        <span class="no">否</span>
                                    {/eq}
                                </div>
                            </td>
                            <td class="">
                                <div class="w50 tc">
                                    {eq name="$vo['status']" value='1'}
                                        <span class="yes" {eq name="'Language@edit'|is_check_access" value="1"}onClick="changeTableVal('language','id','{$vo.id}','status',this);"{/eq}><i class="fa fa-check-circle"></i>是</span>
                                    {else /}
                                        <span class="no" {eq name="'Language@edit'|is_check_access" value="1"}onClick="changeTableVal('language','id','{$vo.id}','status',this);"{/eq}><i class="fa fa-ban"></i>否</span>
                                    {/eq}
                                </div>
                            </td>
                            <!-- <td class="">
                                <div class="w200 tc">
                                    {$vo.url}
                                </div>
                            </td> -->
                            <td class="operation">
                                <div class="w150 tc">
                                    {eq name="'Language@edit'|is_check_access" value="1"}
                                    <a href="javascript:void(0);" data-href="{:url('Language/edit',array('id'=>$vo['id']))}" onclick="openFullframe(this, '编辑语言', '600px', '570px');" class="btn blue">编辑</a>
                                    {/eq}

                                    {if condition="$vo['is_home_default'] == 1 || $vo['mark'] == $main_lang"}
                                        <i></i>
                                        <a class="btn grey" href="javascript:void(0);">同步</a>
                                        <i></i>
                                        <a class="btn grey" href="javascript:void(0);" data-id="{$vo.admin_id}">删除</a>
                                    {else /}
                                        <i></i>
                                        <a class="btn blue" href="javascript:void(0);" data-id="{$vo.id}" onClick="sync_arc(this);">同步</a>
                                        {eq name="'Language@del'|is_check_access" value="1"}
                                        <i></i>
                                        <a class="btn red" href="javascript:void(0)" data-url="{:url('Language/del')}" data-id="{$vo.id}" onClick="delfun(this);">删除</a>
                                        {/eq}
                                    {/if}
                                </div>
                            </td>
                            <td class="sort">
                                <div class="w60 tc">
                                    {eq name="'Language@edit'|is_check_access" value="1"}
                                    <input style="text-align: left;" type="text" onchange="changeTableVal('language','id','{$vo.id}','sort_order',this);" size="4"  value="{$vo.sort_order}" />
                                    {else /}
                                    {$vo.sort_order}
                                    {/eq}
                                </div>
                            </td>
                           
                        </tr>
                        {/foreach}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                {eq name='$main_lang' value='$admin_lang'}
                    <div class="fbutton checkboxall">
                        <input type="checkbox" class="checkAll">
                    </div>
                    {eq name="'Language@del'|is_check_access" value="1"}
                    <div class="fbutton">
                        <a onclick="batch_del(this, 'ids');" data-url="{:url('Language/del')}">
                            <div class="add">
                                <span>批量删除</span>
                            </div>
                        </a>
                    </div>
                    {/eq}
                    <div class="fbutton">
                        <a  href="javascript:void(0);" onclick="tag_call('web_language_switch');">
                            <div class="add">
                                <span>标签调用</span>
                            </div>
                        </a>
                    </div>
                {/eq}
            </div>
            <div style="clear:both"></div>
        </div>
        <!--分页位置-->
        {$page}
    </div>
</div>
<script>
    $(function(){
        $('input[name*=ids]').click(function(){
            if ($('input[name*=ids]').length == $('input[name*=ids]:checked').length) {
                $('.checkAll').prop('checked','checked');
            } else {
                $('.checkAll').prop('checked', false);
            }
        });
        $('input[type=checkbox].checkAll').click(function(){
            $('input[type=checkbox]:not(:disabled)').prop('checked',this.checked);
        });
    });
    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        // 显示顶部菜单语言列表
        append_lang();
        function append_lang(){
            $(".em_lang ul li.lang", window.parent.document).remove();
            var htmlstr = '';
            {volist name='$list' id='vo'}
                htmlstr += '<li class="ey-tool-list text-center lang"><a class="liaojie" href="?lang={$vo.mark}">{$vo.title}</a></li>';
            {/volist}
            $('#addlang', window.parent.document).before(htmlstr);
        }
    });

    function pack_iframe(obj)
    {
        var url = $(obj).data('url');
        //iframe窗
        layer.open({
            type: 2,
            title: '模板语言变量',
            fixed: true, //不固定
            shadeClose: false,
            shade: layer_shade,
            maxmin: false, //开启最大化最小化按钮
            area: ['90%', '90%'],
            content: url,
            end: function(){ //结束弹窗之后的处理

            }
        });
    }
  
    function delfun(obj){
      var title = $(obj).attr('data-typename');
      layer.confirm('<font color="#ff0000">将同步清空该语言的全部数据</font>，确认删除？', {
          shade: layer_shade,
          area: ['480px', '190px'],
          move: false,
          title: '提示',
          btnAlign:'r',
          closeBtn: 3,
          btn: ['确定', '取消'] ,//按钮
          success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function(){
          layer_loading('正在处理');
        // 确定
          $.ajax({
            type : 'post',
            url : $(obj).attr('data-url'),
            data : {del_id:$(obj).attr('data-id'), _ajax:1},
            dataType : 'json',
            success : function(data){
              layer.closeAll();
              if(data.code == 1){
                layer.msg(data.msg, {icon: 1});
                window.location.reload();
                // $('tr[data-id="'+$(obj).attr('data-id')+'"]').remove();
              }else{
                layer.alert(data.msg, {icon: 2, title:false});
              }
            }
          })
        }, function(index){
          layer.close(index);
        }
      );
      return false;
    }
    function tag_call(name)
    {
        $.ajax({
            type: "POST",
            url: "{:url('System/ajax_tag_call', ['_ajax'=>1])}",
            data: {name:name},
            dataType: 'json',
            success: function (res) {
                if(res.code == 1){
                    //询问框
                    var confirm = layer.confirm(res.data.msg, {
                            area: ['780px','350px'],
                            move: false,
                            title: '提示',
                            shade: layer_shade,
                            btnAlign:'r',
                            closeBtn: 3,
                            btn: ['关闭'] ,//按钮
                            success: function () {
                                $(".layui-layer-content").css('text-align', 'left');
                            }
                        }, function(){
                            layer.close(confirm);
                        }
                    );
                }else{
                    layer.alert(res.msg, {icon: 2, title:false});
                }
            },
            error:function(e){
                layer.alert(e.responseText, {icon: 2, title:false});
            }
        });
    }
    
    function sync_arc(obj) {
        var sync_arc_tip = layer.confirm('一键同步和中文主站有关联的栏目文档，将清空该语言下的所有原文档', {
                area: ['480px', '190px'],
                move: false,
                title: '提示',
                shade: layer_shade,
                btnAlign: 'r',
                closeBtn: 3,
                btn: ['确定', '取消'],//按钮
                success: function () {
                    $(".layui-layer-content").css('text-align', 'left');
                }
            }, function () {
                layer.close(sync_arc_tip);
                layer_loading('正在处理');
                var is_jump = 0;
                var id = $(obj).data('id');
                // var is_jump_val = $("#is_jump:checked").val();
                // if ('on' == is_jump_val){
                //     is_jump = 1;
                // }
                $.ajax({
                    type: "POST",
                    url: "{:url('Language/sync', ['_ajax'=>1])}",
                    data: {id: id,is_jump:is_jump},
                    dataType: 'json',
                    success: function (res) {
                        layer.closeAll();
                        if (res.code == 1) {
                            layer.msg(res.msg, {icon: 1});
                        } else {
                            layer.alert(res.msg, {icon: 2, title: false});
                        }
                    },
                    error: function (e) {
                        layer.closeAll();
                        layer.alert(e.responseText, {icon: 2, title: false});
                    }
                });
            }
            , function () {
                layer.close(sync_arc_tip);
            }
        )
        // $(".layui-layer-content").append('<p><input type="checkbox" id="is_jump" checked>跳过已存在文档</p>');

    }
</script>

{include file="public/footer" /}